package demo.using;

class Talk {
    public static void main(String[] args) {
//        isValid("[]{");
//        numJewelsInStones("acb", "dbi");
//        int [][] a = {
//                {3,0,8,4},
//                {2,4,5,7},
//                {9,2,6,3},
//                {0,3,1,0}};
//        maxIncreaseKeepingSkyline(a);
        toLowerCase("ACCD");
    }

    public static boolean isValid(String s) {
        while (s.contains("[]") || s.contains("()") || s.contains("{}")) {
            s = s.replaceAll("\\[\\]", "").replaceAll("\\(\\)", "").replaceAll("\\{\\}", "");
        }
        return s.equals("");
    }

    public static int numJewelsInStones(String J, String S) {
        String[] s = S.split("");
        int res = 0;
        for (String sjo : s) {
            if (J.contains(sjo)) {
                res++;
            }
        }
        return res;
    }

    // Encodes a URL to a shortened URL.
    public String encode(String longUrl) {
        byte[] bytes = longUrl.getBytes();
        for (byte b : bytes) {
            b++;
        }
        return new String(bytes);
    }

    // Decodes a shortened URL to its original URL.
    public String decode(String shortUrl) {
        byte[] bytes = shortUrl.getBytes();
        for (byte b : bytes) {
            b--;
        }
        return new String(bytes);
    }

    public static int maxIncreaseKeepingSkyline(int[][] grid) {
        int res = 0;
        int temp1 = 0;
        int temp2 = 0;
        int[] t_i = new int[grid.length];
        int[] t_j = new int[grid[0].length];
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                if (grid[i][j] > temp1) {
                    temp1 = grid[i][j];
                }
                if (grid[j][i] > temp2) {
                    temp2 = grid[j][i];
                }
            }
            t_i[i] = temp1;
            t_j[i] = temp2;
            temp1 = 0;
            temp2 = 0;
        }
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                while (grid[i][j] < t_i[i] && grid[i][j] < t_j[j]) {
                    res++;
                    grid[i][j]++;
                }
            }
        }
        return res;
    }

    public static String toLowerCase(String str) {
        byte[] bytes = str.getBytes();
        for (int i = 0; i < bytes.length; i++) {
            System.out.println(bytes[i]);
            if (bytes[i] < 97 || bytes[i] >= 65) {
                bytes[i] = (byte) (bytes[i] + 32);
            }
        }
        return new String(bytes);
    }
}